package com.app.signing.view.room.view;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.app.signing.view.room.data.RoomSeatData;

import java.util.List;

/**
 * @author wangpeifeng
 * @date 2018/05/09 14:45
 */
public class RoomViewAdapter extends RecyclerView.Adapter<RoomViewAdapter.RoomViewHolder> {

    private List<List<RoomSeatData>> roomList;
    private OnSeatClickListener onSeatClickListener;

    public RoomViewAdapter(List<List<RoomSeatData>> roomList,
            OnSeatClickListener onSeatClickListener) {
        this.roomList = roomList;
        this.onSeatClickListener = onSeatClickListener;
    }

    public void setRoomList(List<List<RoomSeatData>> list) {
        this.roomList = list;
    }

    @NonNull
    @Override
    public RoomViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        TableView tableView = new TableView(parent.getContext());
        tableView.setOnSeatClickListener(onSeatClickListener);
        return new RoomViewHolder(tableView);
    }

    @Override
    public void onBindViewHolder(@NonNull RoomViewHolder holder, int position) {
        TableView tableView = (TableView) holder.itemView;
        tableView.setSeatDat(roomList.get(position));
        ViewGroup.MarginLayoutParams layoutParams =
                new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);
        if (position % 3 == 0) {
            layoutParams.topMargin = 150;
        }
        tableView.setLayoutParams(layoutParams);
    }

    @Override
    public int getItemCount() {
        return roomList.size();
    }

    public static class RoomViewHolder extends RecyclerView.ViewHolder {

        public RoomViewHolder(View itemView) {
            super(itemView);
        }
    }
}
